var ldm =  {
	httpUrl: '',
	imgUrl: '',
	loginUrl: '',
	url: '', //api地址
	getDevice: navigator.userAgent, //用户设备
	token: '', //令牌
	//  //随机生成4位数
	rand: function(min, max) {
		return Math.floor(Math.random() * (max - min)) + min;
	},
	//  //验证11位手机号码
	verifyPhoneElevent(val) {
		// 		var reg = /^[1][3,4,5,7,8][0-9]{9}$/;
		var reg = /^1[345789]\d{9}$/;
		if (reg.test(val)) {
			return true;
		} else {
			return false;
		}
	},
	isNull(val) {
		var type = typeof(val);
		if (type == 'object') {
			if (val == null) {
				return true;
			} else {
				if (val.length > 0) {
					return false;
				} else {
					return true;
				}
			}
		} else {
			return (val == undefined || val == null || val == "") ? true : false;
		}
	},
	getURI(Uri = 'url') {
		if (this.isNull(this.url)) {
			this.getUrlJson();
		}
		switch (Uri) {
			case 'url':
				return this.url;
				break;
			case 'imgUrl':
				return this.imgUrl;
				break;
			case 'loginUrl':
				return this.loginUrl;
				break;
			case 'httpUrl':
				return this.httpUrl;
				break;
		}

	},
	getUrlJson() {
		var _this = this;
		var ajax = new XMLHttpRequest();
		//设置请求的url参数,参数一是请求的类型,参数二是请求的url,可以带参数,动态的传递参数starName到服务端
		ajax.open('get', 'src/config.json', false);
		ajax.onreadystatechange = function() {
			if (ajax.readyState == 4 && ajax.status == 200) {
				var value = ajax.responseText;
				value = JSON.parse(value);
				_this.url = value.url;
				_this.imgUrl = value.imgUrl;
				_this.loginUrl = value.loginUrl;
				_this.httpUrl = value.httpUrl;
			}
		}
		//发送请求
		ajax.send();
	},
	getUrl() {
		if (!this.url) {
			this.getUrlJson().then(value => {
				this.url = value.data.url;
			});
		}
	},
	//	获取地址栏参数
	getQueryString(key, url) { //获取地址栏参数,如果参数不存在则返回空字符串
		if (typeof(url) == "undefined")
			url = window.location.hash; //window.location.search;
		var re = new RegExp("[?&]" + key + "=([^\\&]*)", "i");
		var a = re.exec(url);
		if (a == null) return "";
		return a[1];
	},
	// 设置缓存
	setCache(key, val) {
		localStorage.setItem(key, JSON.stringify(val));
	},
	//获取缓存
	getCache(key) {
		var userInfo = localStorage.getItem(key);
		if (typeof userInfo == 'string' && userInfo != 'undefined') {
			return JSON.parse(localStorage.getItem(key));
		} else {
			return false;
		}
	},
	// 清除缓存
	clearCache(key) {
		localStorage.removeItem(key);
	},
	toTop() {
		document.body.scrollTop = document.documentElement.scrollTop = 0;
	},
	hasClass(elem, cls) {
		cls = cls || '';
		if (cls.replace(/\s/g, '').length == 0) return false; //当cls没有参数时，返回false
		return new RegExp(' ' + cls + ' ').test(' ' + elem.className + ' ');
	},
	//将图片路径转成base64
	getBase64Image(imgUrl,callback) {
		var image = new Image();
		image.src = imgUrl;
		console.log(image)
		image.onload = function(){
			var canvas = document.createElement("canvas");
			canvas.width = image.width;
			canvas.height = image.height;
			var ctx = canvas.getContext("2d");
			ctx.drawImage(image, 0, 0, image.width, image.height);
			var ext = image.sr
			c.substring(image.src.lastIndexOf(".")+1).toLowerCase();
			var dataURL = canvas.toDataURL("image/"+ext);
			callback(dataURL);
		}
	}
}
